Ccay.Module.define("Ccay.example.ui.igird.showStudent",function(page,$S){
	
	var isAdd = true;
	page.init = function (studentInfo) {
		if (studentInfo)
		{
			isAdd = false;
			studentInfo.birthday = studentInfo.birthday ? Ccay.Format.toDateStr(studentInfo.birthday) : null;
			$S("#showStudentForm").jsonData(studentInfo);
			studentInfo.sex == "1" ? $S("#sexMale").attr("checked", "checked") : $S("#sexFemale").attr("checked", "checked");
			if (studentInfo.city) 
			{
				var cityObj = Ccay.Component.Lookup.getMap("city", null, true);
				$S('#city').manager().setValue(studentInfo.city, cityObj[studentInfo.city]);
			}
			
		}
	};
	
	page.save = function () {
		var showForm = $S("#showStudentForm"), dataObj = {items2Create:[], items2Update:[], items2Delete:[]}, data;
		if (showForm.valid())
		{
			data = showForm.jsonData();
			data.sex = $S("#sexMale").attr("checked") ? "1" : "0";
			data.birthday = data.birthday ? Ccay.Format.toDate(data.birthday) : null;
			if (isAdd) {
				dataObj.items2Create.push(data);
			} else {
				dataObj.items2Update.push(data);
			}
			Ccay.doPut("services/ccay/demo/student/batch", dataObj, function(){
				Ccay.UI.topBox("ccay.common.message.success");
				page.closeDialog();
				$("#iGrid2").manager().reload(false, true);
			});
		}
	};

});